package com.lottery.im.module.chat.presenter;

import android.app.Activity;
import com.lottery.im.MyApplication;
import com.lottery.im.api.ApiClient;
import com.lottery.im.api.observer.ShowTipListObserver;
import com.lottery.im.api.result.entity.GroupNotice;
import com.lottery.im.base.BaseFragmentPresenter;
import com.lottery.im.module.chat.view.GroupNoticeListView;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class GroupNoticeListPresenter extends BaseFragmentPresenter<GroupNoticeListView> {

  public GroupNoticeListPresenter(Activity activity,
      GroupNoticeListView iView,
      LifecycleProvider<FragmentEvent> provider) {
    super(activity, iView, provider);
  }

  public void groupNoticeGetAll(String id) {
    ApiClient.getApiRetrofitInstance()
        .groupNoticeGetAll(MyApplication.getInstance().getUserInfo().getUserId(),
            MyApplication.getInstance().getToken(), id)
        .throttleFirst(2, TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(provider.bindToLifecycle())
        .subscribe(new ShowTipListObserver<GroupNotice>(activity) {
          @Override public void onSuccess(List<GroupNotice> t) {
            iView.getSuccess(t);
          }
        });
  }
}
